//package com.vpen.account.demo.filter;
//
//import com.vpen.account.demo.utils.IpUtils;
//import com.vpen.account.demo.utils.RsaUtils;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.http.HttpMethod;
//import org.springframework.lang.Nullable;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletRequestWrapper;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * 描述:对密码解密
// *
// * @author 韦鹏
// * @date 2022/7/19 10:59
// */
//@Slf4j
//public class LoginPasswordDecryptFilter extends OncePerRequestFilter {
//    /**
//     * 匹配登录的连接
//     */
//    private static final AntPathRequestMatcher DEFAULT_ANT_PATH_REQUEST_MATCHER = new AntPathRequestMatcher("/api/web/account/login", HttpMethod.POST.name());
//
//    @Override
//    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
//            throws ServletException, IOException {
//        log.debug("访问者ip:{}", IpUtils.getIpAddress(request));
//        if (DEFAULT_ANT_PATH_REQUEST_MATCHER.matcher(request).isMatch()) {
//            filterChain.doFilter(new FormContentRequestWrapper(request), response);
//        } else {
//            filterChain.doFilter(request, response);
//        }
//    }
//
//
//    private static class FormContentRequestWrapper extends HttpServletRequestWrapper {
//
//        public FormContentRequestWrapper(HttpServletRequest request) {
//            super(request);
//        }
//
//        @Override
//        @Nullable
//        public String getParameter(String name) {
//            String value = super.getParameter(name);
//            if (UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY.equals(name)) {
//                // 解密操作
//                value = RsaUtils.decryptStr(value);
//            }
//            return value;
//        }
//    }
//
//
//}
